﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace TB_WS.Class
{
    public class Rate_Control
    {
        public static void INSERT_Rate(int Seller_ID,string Buyer_Nick,string Tids,string Rate_Type,string Rate_Detail)
        {
            string sql = "insert into Rate_List values('" + Buyer_Nick + "','" + Tids + "','" + Rate_Type + "','" + Rate_Detail + "'," + Seller_ID + ",'" + DateTime.Now.ToString() + "')";
            Class.Unit.db_Conn.Nonquery(sql);
        }

        public static int Get_Rate_Count(string Buyer_Nick,string Rate_Detail)
        {
            string sql = "select count(*) from Rate_List where Buyer_Nick='" + Buyer_Nick + "' and Rate_Detail='" + Rate_Detail + "'";
            return Convert.ToInt32(Class.Unit.db_Conn.scalar(sql));
        }

        public static DataSet Get_Rate_Use_Buyer_Nick(string Buyer_Nick)
        {
            string sql = "select * from Rate_List where Buyer_Nick='" + Buyer_Nick + "' order by id desc";
            return Class.Unit.db_Conn.select(sql);
        }

        public static DataSet Get_Top_Rate(string Rate_Type,int Top)
        {
            if (Rate_Type == "All")
            {
                string sql = "select top " + Top + " * from Rate_List order by id desc";
                return Class.Unit.db_Conn.select(sql);
            }
            else
            {
                string sql = "select top " + Top + " * from Rate_List where Rate_Type='"+Rate_Type+"' order by id desc";
                return Class.Unit.db_Conn.select(sql);
            }
        }

        public static void Update_Rate(int Rate_id,string New_Rate_Detail)
        {
            string sql = "update Rate_List set Rate_Detail='" + New_Rate_Detail + "' where id=" + Rate_id;
            Class.Unit.db_Conn.Nonquery(sql);
        }

        public static int Get_FW_Tid_Pushed(string Tid)
        {
            string sql = "select count(*) from FireWall_Pushed where Tid='" + Tid + "'";
            return Convert.ToInt32(Class.Unit.db_Conn.scalar(sql));
        }

        public static int Insert_FW_Tid(string Tid)
        {
            string sql = "insert into FireWall_Pushed values('" + Tid + "')";
            return Class.Unit.db_Conn.Nonquery(sql);
        }
    }
}
